package com.ifonly.ar.sql;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ifonly
 * @version 1.0 2015-12-07 10:04
 * @since JDK 1.6
 */
public class MapResultSetHandler {

    public static Map<String, Object> handle(ResultSet rs) throws SQLException {
        Map<String, Object> map = new HashMap<String, Object>();
        ResultSetMetaData rsmd = rs.getMetaData();
        int columnCount = rsmd.getColumnCount();

        for (int i = 1; i <= columnCount; i++) {
            String column = rsmd.getColumnName(i);
            Object value = rs.getObject(i);
            map.put(column, value);
        }
        return map;
    }

}
